package model

import (
	"baidu_rpc/kitex_gen/baidu_rpc/user"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:varchar(20)" json:"mobile,omitempty"`
	Password string `gorm:"type:varchar(32)" json:"password,omitempty"`
}

func (u *User) GetCover(db *gorm.DB, Page int64, Size int64) (list []*user.GetUserList, err error) {
	page := Page
	if page <= 0 {
		page = 1
	}

	pageSize := Size
	
	switch {
	case pageSize > 100:
		pageSize = 100
	case pageSize <= 0:
		pageSize = 10
	}

	offset := (page - 1) * pageSize

	err = db.Model(u).Offset(int(offset)).Limit(int(pageSize)).Find(&list).Error

	return list, err

}
